<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<h3>회원정보 수정</h3>
<form id="updateForm" action="member.do" method="post" enctype="multipart/form-data">
<input type="hidden" name="mode" value="update">
<table>
<tr>
<td>아이디(E-mail)</td>
<td><input type="hidden" name="id" value="${sessionScope.mvo.id }">${sessionScope.mvo.id }
</td>
</tr>
<tr>
<td>비밀번호</td>
<td><input type="password" name="password" id="up_password"></td>
</tr>
<tr>
<td>비밀번호 확인</td>
<td><input type="password" id="up_passwordCheck"></td>
</tr>
<tr>
<td>닉네임</td>
<td><input type="text" name="nickname" id="up_nickname" value="${sessionScope.mvo.nickname }"></td>
</tr>
<tr>
<td>프로필사진</td>
<td><img src="/img/profile/${sessionScope.mvo.proImg }"><br>
<input type="file" name="uploadImg" id="up_uploadImg"></td>
</tr>
<tr>
<td>자기소개</td>
<td><textarea rows="5" cols="20" name="info" id="up_info">${sessionScope.mvo.info }</textarea><span id="up_info_length">0</span>&nbsp;/100
</tr>
<tr>
<td><input type="button" id="leaveBtn" value="탈퇴하기"></td>
<td><input type="button" id="updateBtn" value="수정하기"></td>
</tr>
</table>
<input type="hidden" name="uId" value="${sessionScope.mvo.uId }">
<input type="hidden" name="level" value="${sessionScope.mvo.level }">
</form>
<script type="text/javascript">
$("#updateBtn").click(function(){
	if($("#up_password").val()==""){
		alert("패스워드를 입력하세요");
		$("#up_password").focus();
		return;
	}else if($("#up_password").val().length<4){
		alert("비밀번호는 4자리 이상 입력하세요");
		$("#up_password").focus();
		return;
	}
	if($("#up_passwordCheck").val()!=$("#up_password").val()){
		alert("패스워드를 확인해주세요");
		$("#up_passwordCheck").val("").focus();
		return;
	}
	if($("#up_nickname").val()==""){
		alert("닉네임을 입력하세요");
		$("#up_nickname").focus();
		return;
	}
	if($("#up_uploadImg").val()!=""){
		if($("#up_uploadImg")[0].files[0].size>3145728){
			alert("3MB 이하로 업로드해주세요!!");
			$("#up_uploadImg").val("");
			return;
		}
	}
	$("#updateForm").submit();
});
$("#leaveBtn").click(function(){
	if(confirm("탈퇴하시겠습니까?")){
		if("${sessionScope.mvo.password}"==$("#up_password").val()&&$("#up_passwordCheck").val()==$("#up_password").val()&&$("#up_password").val()!=""){
			location.href="member.do?mode=leave";
		}else{
			alert("패스워드를 확인해주세요");
			$("#up_password").val("").focus();
			$("#up_passwordCheck").val("");
			return;
		}
	}
});
$("#up_info").keyup(function(){
	var textlength = $("#up_info").val().length;
	var now = 100 - textlength;
	if(now < 0){
		var str = $("#up_info").val();
		$("#up_info").focus();
		var inputVal = str.substr(0, 100);
		alert("100자를 초과하였습니다.");
		now=0;
		$("#up_info").val(inputVal);
	}
	$("#up_info_length").text(textlength);
	
});
</script>